'use strict';
//我的积分
import React,{Component} from 'react';
import Header from '../../common/header';
import * as URLconstant from '../../constant/URLconstant'
import Util from '../../common/util';
import {
    View,
    Text,
    TouchableOpacity,
    Image,
    StyleSheet,
    ScrollView
} from 'react-native';
export default class myIntegral extends Component{
    // 构造
      constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            coinData:null
        };
      }

    componentDidMount() {
        this.getCoin()
    }

    getCoin(){
        let url=URLconstant.MY_COIN
        let datakey=[]
        datakey['user_id']=this.props.user_id
        Util.get(url,datakey,this.getCoinSuc.bind(this),this.errorCallback.bind(this))
    }

    getCoinSuc(datas){
        if(datas.status==0){
            this.setState({
                coinData:datas.data
            })
        }
    }
    errorCallback(err){

    }

      render(){
          let coinData = this.state.coinData
          return(
              <View style={{flex:1,backgroundColor:"#f0f0f0"}}>
                  <Header navigator={this.props.navigator} initObj={{ title: '我的积分',id:2}}/>
                  {
                      this.state.coinData==null?
                          <View style={{flex:1}}>
                              {Util.loading}
                          </View>
                          :
                          <View>
                              <View style={styles.coin_view}>
                                <Text style={{fontSize:16,color:"#fff",marginBottom:10}}>可使用积分</Text>
                                  <Text style={{fontSize:30,color:"#fff"}}>{coinData.memberNowCoin}</Text>
                              </View>
                              <View style={styles.coin_view_two}>
                                  <View style={[styles.coin_view_item,styles.border_b]}>
                                      <View>
                                          <Text style={{fontSize:14,color:"#333",marginBottom:5}}>已使用</Text>
                                          <Text style={{fontSize:12,color:"#666"}}>已经使用的积分</Text>
                                      </View>
                                      <Text style={{fontSize:18,color:"#5886ff"}}>{coinData.memberUseCoin}</Text>
                                  </View>
                                  <View style={styles.coin_view_item}>
                                      <View>
                                          <Text style={{fontSize:14,color:"#333",marginBottom:5}}>历史总积分</Text>
                                          <Text style={{fontSize:12,color:"#666"}}>历史总获得积分数</Text>
                                      </View>
                                      <Text style={{fontSize:18,color:"#5886ff"}}>{coinData.memberSumCoin}</Text>
                                  </View>
                              </View>
                          </View>
                  }
              </View>
          )
      }
}
var styles = StyleSheet.create({
    coin_view:{
        backgroundColor:"#5886ff",
        height:180,
        alignItems:'center',
        justifyContent:'center',
    },
    coin_view_two:{
        paddingHorizontal:10,
        backgroundColor:"#fff"
    },
    coin_view_item:{
        height:65,
        flexDirection:'row',
        alignItems:'center',
        justifyContent:'space-between'
    },
    border_b:{
        borderBottomWidth:1,
        borderBottomColor:"#e0e0e0"
    }
})